﻿using CleanArchitecture.Infrastructure.Interfaces.SystemTasks;
using CleanArchitecture.Infrastructure.Services.SystemTasks;
using CleanArchitecture.Web.Filters;
using Microsoft.AspNetCore.Mvc;

namespace CleanArchitecture.Web.Controllers.Backend
{
    public partial class SystemScheduleTaskController : Controller
    {
        private readonly ISystemTaskService _scheduleTaskService;

        public SystemScheduleTaskController(ISystemTaskService scheduleTaskService)
        {
            _scheduleTaskService = scheduleTaskService;
        }

        [HttpPost]
        //[AuthorizeAdmin(Core.Configuration.AuthorizeType.AdminOnly)]
        public virtual IActionResult RunTask(string taskType)
        {
            var scheduleTask = _scheduleTaskService.GetTaskByType(taskType);
            if (scheduleTask == null)
                //schedule task cannot be loaded
                return NoContent();

            var task = new ProcessTask(scheduleTask);
            task.Execute();

            return NoContent();
        }
    }
}